$(function(){
	/* cart animation start 02-28 */
	
	var eleFlyElement = document.querySelector(".fly_item"), eleShopCart = document.querySelector(".service-cart");
	var cur_num=$('.cart-num1').html();	
	var myParabola = funParabola(eleFlyElement, eleShopCart, {
		speed: 400, 
		curvature: 0.0008,
		complete: function() {
			eleFlyElement.style.visibility = "hidden";
			eleShopCart.querySelector(".cart-num").innerHTML = ++cur_num;
		}
	});
	
	if (eleFlyElement && eleShopCart) {
		[].slice.call(document.getElementsByClassName("detail-to-cart")).forEach(function(button) {
			button.addEventListener("click", function(event) {
				var img_pos=$('.detail-sale .selected img').attr('src');
				$('.fly_item img').attr('src',img_pos);
				var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
					scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
				eleFlyElement.style.left = event.clientX + scrollLeft + "px";
				eleFlyElement.style.top = event.clientY + scrollTop + "px";
				eleFlyElement.style.visibility = "visible";
				myParabola.position().move();	
				$(".msg").show().animate({width: '250px'}, 300).fadeOut(1000);	
			});
		});
	}
	/* cart animation end 02-28 */
	
	/* collect */
	$('.detail-collect').click(function(e) {
        $('.detail-collect em').removeClass('collection-icon1').addClass('collection-icon');
		$(this).children('span').html('已收藏');
    });
	
	var _height = $(".detail-nav").offset().top;
	$(document).scrollTop() > _height && $(".detail-nav").addClass("nav-fixed"),
        $(window).scroll(function() {
            $(".detail-nav").offset().top;
            $(window).scrollTop() < _height ? $(".detail-nav").hasClass("nav-fixed") && $(".detail-nav").removeClass("nav-fixed") : $(".detail-nav").addClass("nav-fixed")
        })
    $('.detail-img-s .detail-sale ul li').not('.disabled').click(function(){
    	$('.detail-img-s .detail-sale ul li').removeClass('selected');
    	$(this).addClass('selected');
    });
    $('.detail-common .detail-sale ul li').not('.disabled').click(function(){
    	$('.detail-common .detail-sale ul li').removeClass('selected');
    	$(this).addClass('selected');
    });

    $('.increase-i').click(function(){
    	var num = Number($('.detail-text').val());
    	num++;
    	if (num > 99) {
    		num = 99;
    	}
    	$('.detail-text').val(num);
    });
    $('.decrease-i').click(function(){
    	var num = Number($('.detail-text').val());
    	console.log(num)
    	num--;
    	if (num < 2) {
            num = 1;
        }

    	$('.detail-text').val(num);
    });

    $(window).scroll(function(){
    	var h1 = $('#detail-nav1').offset().top,
	    	h2 = $('#detail-nav2').offset().top,
	    	h3 = $('#detail-nav3').offset().top,
	    	h4 = $('#detail-nav4').offset().top,
	    	h5 = $('#detail-nav5').offset().top,
	    	h6 = $('#detail-nav6').offset().top,
	    	dh = $(document).scrollTop();
    	if (dh>h1 && dh<h2) {
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(0)).css('color','#d41439');
    	}else if (dh>h2 && dh<h3) {
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(1)).css('color','#d41439');
    	}else if (dh>h3 && dh<h4) {
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(2)).css('color','#d41439');
    	}else if(dh>h4 && dh<h5){
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(3)).css('color','#d41439');
    	}else if (dh>h5 && dh<h6) {
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(4)).css('color','#d41439');
    	}
    	else{
    		$('.detail-item a').css('color','#666');
    		$($('.detail-item a').get(5)).css('color','#d41439');
    	}
    });

    var srcInit = $($('.detail-lit-con li img').get(0)).attr('src');	
    $('.detail-img-big').children('img').attr('src',srcInit);
    $('.detail-lit-con li').mouseover(function(){
    	var srcInit = $(this).children('img').attr('src');	
    	$('.detail-img-big').children('img').attr('src',srcInit);
    });
    
    if ($('.detail-lit-con ul li').length>5) {
    	$('.detail-arr-down').click(function(){
	    	$('.detail-lit-con ul').css('top',-83);
	    });
    }
    $('.detail-arr-up').click(function(){
    	$('.detail-lit-con ul').css('top',0);
    });
});